<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('养修服务单项列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            名称：<input type="text" name="name"/>
                        </li>
                        <li>
                            是否套餐：<select name="carPackage" th:with="type=${@dict.getType('bus_car_ackage')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            服务分类：<select name="serviceCatalog" th:with="type=${@dict.getType('bus_car_catalog')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            审核状态：<select name="auditStatus" th:with="type=${@dict.getType('si_audit_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            上架状态：<select name="saleStatus" th:with="type=${@dict.getType('si_sale_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                <i class="fa fa-plus"></i> 新增
            </a>
<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
<!--               shiro:hasPermission="system:post:remove">-->
<!--                <i class="fa fa-remove"></i> 删除-->
<!--            </a>-->

            <a class="btn btn-warning auditBtn" id="auditBtn" onclick="startAudit()">
                <i class="fa fa-file-audio-o"></i> 发起审核
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var carAckage = [[${@dict.getType('bus_car_ackage')}]];
    var carCatalog = [[${@dict.getType('bus_car_catalog')}]];
    var audit = [[${@dict.getType('si_audit_status')}]];
    var sale = [[${@dict.getType('si_sale_status')}]];
    var prefix = ctx + "business/serviceItem";

    $("#bootstrap-table").on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table load-success.bs.table",function () {
        //判断只有套餐才会变亮
        let rows = $("#bootstrap-table").bootstrapTable("getSelections");//获取参数
        if (rows.length!=1){
            $("#auditBtn").addClass("disabled");
            return;
        }
        //只有一条数据这条是记录数
        let row = rows[0];
        if (!row.carPackage){
            $("#auditBtn").addClass("disabled");
            return;
        }
        //处于审核中或者处于审核通过
        if (row.auditStatus==1 || row.auditStatus==2){
            $("#auditBtn").addClass("disabled");
            return;
        }

        $("#auditBtn").removeClass("disabled");

    });

    function startAudit(){
        var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
        $.modal.open("发起审核",prefix+"/auditPage/"+row.id);
    }
    function up(id) {
        table.set();
        $.modal.confirm("确认需要上架该服务吗?", function() {
            var url = prefix + "/ItemUp?id="+id;
            $.operate.get(url);
        });
    }
    function next(id) {
        table.set();
        $.modal.confirm("确认需要下架该服务吗?", function() {
            var url = prefix + "/ItemNext?id="+id;
            $.operate.get(url);
        });
    }

    $(function () {
        var options = {
            url: prefix + "/query", //查询数据地址
            createUrl: prefix + "/addPage", //添加数据地址
            updateUrl: prefix + "/editPage/{id}", //编辑页面地址
            removeUrl: prefix + "/remove", //删除数据地址
            exportUrl: prefix + "/export",
            sortName: "id", //排序名称
            modalName: "养修服务单项", //模态框名称
            pagination:true,//分页功能
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '服务项编号'
                },
                {
                    field: 'name',
                    title: '服务项名称',
                    sortable: true
                },
                {
                    field: 'originalPrice',
                    title: '服务项原价',
                    sortable: true
                },
                {
                    field: 'discountPrice',
                    title: '服务项折扣价',
                    sortable: true
                },
                {
                    field: 'carPackage',
                    title: '是否套餐',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(carAckage, value);
                    }
                },
                {
                    field: 'serviceCatalog',
                    title: '服务分类',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(carCatalog, value);
                    }
                },
                {
                    field: 'info',
                    title: '备注',
                    sortable: true,
                    formatter:function (value,row,index) {
                        return $.table.tooltip(value,10,"open")
                    }
                },
                {
                    field: 'auditStatus',
                    title: '审核状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(audit, value);
                    }
                },
                {
                    field: 'saleStatus',
                    title: '上架状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(sale, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        //审核状态
                        var auditStatus = row.auditStatus;
                        let disabled = '';
                        //审核中不能进行编辑
                        if (auditStatus == 1 ){
                            disabled = "disabled";
                        }
                        actions.push('<a class="btn btn-success btn-xs '+ disabled+' '+editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        //初始化disabled
                        disabled = '';
                        if (!row.saleStatus){
                            //下架状态,进行上架
                            //对于 初始化,审核中,重新调整 不能点击
                            if (auditStatus == 0 || auditStatus == 1 || auditStatus == 3){
                                disabled = "disabled";
                            }
                            actions.push('<a class="btn btn-info btn-xs '+ disabled +'" href="javascript:void(0)" ' +
                                'onclick="up(\'' + row.id + '\')"><i class="fa fa-shopping-cart"></i>上架</a> ');
                        }else {
                            //上架状态,进行下架
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" ' +
                                'onclick="next(\'' + row.id + '\')"><i class="fa fa-anchor"></i>下架</a> ');
                        }
                        //初始化disabled
                        disabled = '';
                        //审核中不能进行删除
                        if (auditStatus == 1){
                            disabled = "disabled";
                        }
                        actions.push('<a class="btn btn-danger btn-xs '+disabled+' ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });
</script>
</body>
</html>